//index.js
//获取应用实例
const app = getApp()
const util = require('../../utils/util.js')
Page({
    data: {
        imgUrls: [
            'https://img.mukewang.com/szimg/59b8a4910001cb0509000500.jpg',
            'https://img.mukewang.com/szimg/59b8a4910001cb0509000500.jpg',
            'https://img.mukewang.com/szimg/59b8a4910001cb0509000500.jpg'
        ],
        indicatorDots: false,
        autoplay: false,
        interval: 5000,
        duration: 1000,
        systemInfo: app.systemInfo,
        list: [],
        bannerHeight: "200",
        workList: [],
        advert: null,
        ii: 0
    },
    scrollBottom() {

        console.log(this.data.ii++)
    },
    imgs: function(e) { //单广告位图片高度
        util.imgHeight(e, (data) => {
            var viewHeight = (this.data.systemInfo.screenWidth - 20) / data;
            this.setData({
                bannerHeight: viewHeight
            })
        })
    },
    goto: function(e) {
        console.log(e.currentTarget.dataset.id)
        let pageId = e.currentTarget.dataset.id
        wx.navigateTo({
            url: '/pages/details/index?pageId=' + pageId
        });
    },
    gotoClass: function(e) {
        console.log(e.currentTarget.dataset.id)
        let classid = e.currentTarget.dataset.id
        wx.navigateTo({
            url: '/pages/classification/index?classId=' + classid
        });
    },
    getUserinfo: function(e) {
        console.log(e)
        app.userInfo = e.userInfo
        wx.switchTab({
            url: '/pages/index/index'
        })
    },
    getBanner: function() {
        console.log(app.apiurl)
        let _self = this
        util.postRequest('FinanceManage/rest/paramInit.do', { openId: app.openId }, function(res) {
            console.log(res)
            _self.setData({
                imgUrls: res.initList
            })
        })
    },
    getClass: function() { //获取分类
        console.log(app.openId)
        let _self = this
        util.postRequest('FinanceManage/rest/typeInit.do', { openId: app.openId }, function(res) {
            console.log(res)
            _self.setData({
                list: res.initList
            })
        })

    },
    getAdvert() {
        let _self = this
        util.getAdvert({ openId: app.openId }, function(res) {
            console.log(res)
            _self.setData({
                advert: res
            })
        })
    },
    getNewWork() {
        let _self = this
        util.postRequest('FinanceManage/rest/articleNewestList.do', { openId: app.openId, newestCount: 20 }, function(res) {
            console.log(res)
            _self.setData({
                workList: res.articleList
            })
        })
    },
    onLoad: function() {
        wx.cloud.init()
        wx.cloud.callFunction({
            name: 'getUserInfo',
        }).then(
            res => {
                console.log(res)
                app.openId = res.result.openId
                console.log(app.openId)
                this.getBanner()
                this.getClass()
                this.getAdvert()
                this.getNewWork()
            }
        )
        let data = {
            openId: app.openId
        }
        util.postRequest('FinanceManage/rest/memberDetail.do', data, function(res) {
            console.log(res)
            util.setStorage('userInfo', res.bean)
        })

    },

})